#include "client.h"
#include "onlineuser.h"
#include "ui_onlineuser.h"

OnlineUser::OnlineUser(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OnlineUser)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_QuitOnClose, false);
}

OnlineUser::~OnlineUser()
{
    delete ui;
}

void OnlineUser::updateOnlineUserWigetList(QStringList &userlist)
{
    ui->onlineUser_LW->clear();
    ui->onlineUser_LW->addItems(userlist);
}

void OnlineUser::on_onlineUser_LW_itemDoubleClicked(QListWidgetItem *item)
{
    QString strCurName = Client::getInstance().m_strLoginName;
    QString strTarName = item->text();

    PDU* pdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, 0);
    memcpy(pdu->caData     , strCurName.toStdString().c_str(), 32);
    memcpy(pdu->caData + 32, strTarName.toStdString().c_str(), 32);

    Client::getInstance().sendMsg(pdu);
}
